package com.zj.controller;

import com.zj.pojo.Apple;
import com.zj.pojo.Result;
import com.zj.services.BaseService;
import com.zj.services.FarmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("farmer")
public class FarmerController {
    @Autowired
    private BaseService service;

    @GetMapping("/{id}")
    public Result getApple(@PathVariable int id) {
        Apple apple = service.getAppleById(id);
        return new Result(HttpStatus.OK.value(), "query success",apple);
    }
    @PostMapping("/add")
    public Result addApple(@RequestBody Apple apple){
        int size = service.insertApples(apple);
        return new Result<>(HttpStatus.OK.value(), "insert success",size);
    }

    @PutMapping("/{id}")
    public Result updateApple(@PathVariable int id,@RequestBody Apple apple){
        List<Apple> apppool = service.updateAppleById(id,apple);
        return new Result<>(HttpStatus.OK.value(), "update success",apppool);
    }
    @GetMapping("/all")
    public Result getAll(){
        List<Apple> apppool = service.getApppool();
        return new Result<>(HttpStatus.OK.value(), "query all success",apppool);
    }
    @DeleteMapping("/{id}")
    public Result deleteApple(@PathVariable int id){
        List<Apple> apppool=service.deleteApple(id);
        return new Result<>(HttpStatus.OK.value(), "delete success",apppool);

    }



}
